package com.mallcloud.mall.app.service.impl;

import com.mallcloud.mall.admin.api.entity.SysUser;
import com.mallcloud.mall.app.mapper.AppProcedureMapper;
import com.mallcloud.mall.app.service.AppWxUserService;
import com.mallcloud.mall.common.core.exception.FailException;
import com.mallcloud.mall.common.data.resolver.TenantResolver;
import com.mallcloud.mall.mall.api.entity.dto.ProAutoLogin;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class AppWxUserServiceImpl implements AppWxUserService {
    private final AppProcedureMapper procedureMapper;

    @Override
    public String mallLoginOrRegister(SysUser sysUser) {
        ProAutoLogin dto = new ProAutoLogin();
        dto.setMobile(sysUser.getPhone());
        dto.setOpenid(sysUser.getMiniOpenid());
        dto.setStoreNo(TenantResolver.getById().getCode());

        procedureMapper.autoLogin(dto);
        if (!dto.isSuccess()) {
            log.error("失败");
            throw new FailException(dto.getMessage());
        }
        return dto.getCardNo();
    }
}